package com.ibeeking.found.upms.cp.rest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ibeeking.found.upms.cp.rest.service.ICpRolePermissionService;
import com.ibeeking.found.upms.cp.rest.service.ICpTpRolePermissionService;
import com.ibeeking.found.upms.service.common.bo.CpRolePermissionBO;
import com.ibeeking.found.upms.service.common.dos.CpRolePermissionDO;
import com.ibeeking.found.upms.service.common.dos.CpTpRolePermissionDO;
import com.ibeeking.found.upms.service.mapper.CpRolePermissionMapper;
import com.ibeeking.found.upms.service.mapper.CpTpRolePermissionMapper;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.json.JsonUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName CpRolePermissionServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2021-05-13 11:40
 **/
@Service
public class CpTpRolePermissionServiceImpl implements ICpTpRolePermissionService {

    @Resource
    private CpTpRolePermissionMapper cpTpRolePermissionMapper;

    @Override
    public List<CpRolePermissionBO> queryRolePermissionByRoleIds(List<Long> roleIds) {
        List<CpTpRolePermissionDO> rolePermissionDos = cpTpRolePermissionMapper.selectList(new LambdaQueryWrapper<>(CpTpRolePermissionDO.class).in(CpTpRolePermissionDO::getRoleId, roleIds));
        if (Collections3.isEmpty(rolePermissionDos)) {
            return Collections3.emptyList();
        }
        return JsonUtils.jsonToList(rolePermissionDos, CpRolePermissionBO.class);
    }
}
